/*
 * Project: Preditor2
 * File:    ExceptionRenderer.java
 * Created: Sep 23, 2004
 * By:      critchie
 * 
 * (C) 2004 Ontira Communications Inc.
 */
package com.googlecode.ddlutilstool.logging;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.log4j.or.ObjectRenderer;

/**
 * A Log4J renderer of exceptions.  It simply
 * dumps the stack trace. 
 * 
 */
public class Log4JExceptionRenderer implements ObjectRenderer {

	/**
	 * 
	 */
	public Log4JExceptionRenderer() {
		super();
	}

	/**
	 * @see org.apache.log4j.or.ObjectRenderer#doRender(java.lang.Object)
	 */
	public String doRender(Object pObject) {
		if (pObject!=null && pObject instanceof Exception) {
			Exception exception = (Exception) pObject;

			StringWriter stringWriter = new StringWriter();
			PrintWriter printWriter = new PrintWriter(stringWriter);

			exception.printStackTrace(printWriter);

			return stringWriter.toString();
		}
		else if (pObject!=null) {
			return pObject.toString();
		}
		else {
			return "";
		}
	}

}
